# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=nftables
pkgver=0.9.6
pkgrel=0
pkgdesc="Netfilter tables userspace tools"
url="https://netfilter.org/projects/nftables"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	asciidoc
	bison
	docbook2x
	flex
	gmp-dev
	jansson-dev
	libmnl-dev
	libnftnl-dev
	ncurses-dev
	readline-dev
	"
install="$pkgname.post-upgrade"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc"
source="https://netfilter.org/projects/nftables/files/nftables-$pkgver.tar.bz2
	nftables.confd
	nftables.initd
	nftables.nft
	"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	sed -i '1i#include "config.h"' "$builddir"/src/proto.c
}

build() {
	CONFIG_MAN=y DB2MAN=docbook2x-man ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/usr/share \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--with-json
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm644 "$srcdir"/nftables.nft "$pkgdir"/etc/nftables.nft
	install -dm755 "$pkgdir"/etc/nftables.d
}

sha512sums="ca6524ff1cb1e79d636afeb96f54e4699773e1cbda8e9a3ec5728f4d5b764c0df16b195cdcc0e304ae5643c8761b6b5a6685c737965a7415aec07aeb9f3dc5df  nftables-0.9.6.tar.bz2
cca875473bbd7b2326afcaeec84b1f9826afb70fc67381a64f3ad104a13a314bd2c352e0fac1f602b9980edb2818bf6242373aa1634ce17bcc1d82eeb8b05b39  nftables.confd
739e704b263b7afd124c5f497fef43c6f5de69f0a75e0a370c2b84f84619ca6a8a64fe704413c2d1cc1e4a0db062cce2c7fb807c202f9a1a1f60152bd45ad914  nftables.initd
059e0920517ff9f9c564bdfda6a06e8392a2755c01f8d0331a8577fd027713948d3f1e2cbe9da5077870181dc9e425d8c69e4c82ea6ee261fced4ab61aff3ad4  nftables.nft"
